package com.cinc.mdm.modules.customer.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cinc.mdm.modules.customer.entity.MdmCustomer;
import com.cinc.mdm.modules.customer.mapper.MdmCustomerMapper;
import com.cinc.mdm.modules.customer.service.IMdmCustomerService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 客户
 * @Author: jeecg-boot
 * @Date:   2022-02-04
 * @Version: V1.0
 */
@Service
public class MdmCustomerServiceImpl extends ServiceImpl<MdmCustomerMapper, MdmCustomer> implements IMdmCustomerService {


    @Override
    public Map<String, Object> queryCountStatFp() {
        Map<String, Object> data = new HashMap<>();
        // 本年总数
        int sumCount = baseMapper.selectCountThisYear();
        data.put("sumCount", sumCount);
        // 本年各月数
        List<Map<String, Integer>> curMonthCountList = baseMapper.selectMonthCountThisYear();
        Map<String, Integer> curMonthMap = new HashMap<>();
        curMonthCountList.forEach(curMonthCount -> curMonthMap.put(curMonthCount.get("month")+"", curMonthCount.get("count")));
        List<Map<String, Object>> monthCountList = new ArrayList<>();
        for(int i =1; i<= 12; i++){
            Map<String, Object> monthCount = new HashMap<>();
            monthCount.put("x", i+"月");
            if(curMonthMap != null && curMonthMap.containsKey(i+"")){
                monthCount.put("y", curMonthMap.get(i+""));
            }else{
                monthCount.put("y", 0);
            }
            monthCountList.add(monthCount);
        }
        data.put("monthCountList", monthCountList);

        return data;
    }
}
